#pragma once
#include"HashTable.hpp"
namespace bit
{
template<class K,class V,class Hash=hash_bucket::HashFunc<K>>
class unordered_map
{
public:
    class MapKeyOfT
    {
    public:
        const K& operator()(const pair<K,V>& kv)
        {
            return kv.first;
        }
    };
    
    typedef typename hash_bucket::HashTable<K, pair<const K,V>, MapKeyOfT,Hash>::iterator iterator;
   // typedef typename hash_bucket::HashTable<K, pair<const K,V>, MapKeyOfT,Hash>::const_iterator const_iterator;
    iterator begin()
    {
        return _ht.begin();
    }

    iterator end()
    {
        return _ht.end();
    }
    
//    const_iterator begin() const
//    {
//        return _ht.begin();
//    }
//
//    const_iterator end() const
//    {
//        return _ht.end();
//    }
    
    pair<iterator, bool>insert(const pair<K, V>& kv)
    {
        return  _ht.Insert(kv);
    }
    
    void print()
    {
        _ht.Print();
    }
    
private:
    
    hash_bucket::HashTable<K,pair<const K,V>,MapKeyOfT,Hash> _ht;
};

void test_map()
{
    unordered_map<string,string> dict;
    
    dict.insert(make_pair("launch", "发起、下水"));
    dict.insert(make_pair("resource", "资源"));
    dict.insert(make_pair("source", "根源"));
    dict.insert(make_pair("dirive", "起源"));
    dict.insert(make_pair("marine", "海洋的、海军士兵"));
//
   /// dict.print();
    auto it=dict.begin();

    while(it!=dict.end())
    {
        cout<<it->first<<":"<<it->second<<endl;
        it->second+='x';
        ++it;
    }
    cout<<endl;
    
    
    for(auto& ch:dict)
    {
        cout<<ch.first<<":"<<ch.second<<endl;
    }
}
}
